import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/**
 * Creates Launcher GUI to launch a Server or Client from.
 *
 * @author BluJaded Team
 * @version (see Sourceforge.net)
 */
public class LaunchGui extends JFrame implements MouseListener, WindowListener {
    
    private JFrame frame;
    private JButton serverB;
    private JButton clientB;
    
    /**
     * Creates the Launcher GUI from which a user can then create a server or a client from.
     */
    private LaunchGui()
    {
        super();
        frame = new JFrame("Welcome to JadeTalk");
        Container contentPane = frame.getContentPane();
        contentPane.setLayout(new BorderLayout());
        Container buttonPanel = new JPanel();
        buttonPanel.setLayout(new FlowLayout());
        serverB = new JButton("Server");
        serverB.addMouseListener (this);
        buttonPanel.add(serverB);
        buttonPanel.add (new JLabel (" or a "));
        clientB = new JButton("Client");
        clientB.addMouseListener (this);
        buttonPanel.add(clientB);
        JLabel label = new JLabel("Do you wish to run a :");
        label.setHorizontalAlignment(0);
        contentPane.add (label, BorderLayout.NORTH);
        contentPane.add(buttonPanel, BorderLayout.CENTER);
        frame.addWindowListener(this);
        frame.setResizable(false);
        frame.pack();
        frame.setVisible(true);
    }    
    
 /**
  * mouseClicked Event occurs when the mouse if clicked on a listening object.
  * 
  * @param      e    the mouseEvent object assosiated with the event.
  */         
  public void mouseClicked(MouseEvent e) {
     // If button pressed is to create Server
     if (e.getSource().equals(serverB)){
         ServerGui.main(new String[] {});
         frame.dispose();
     }

     // If button pressed is to create a Client
     if (e.getSource().equals(clientB)){
         ClientInputGui.main(new String[] {});
         frame.dispose();
     }
  }
    

  public void mouseEntered(MouseEvent e) {}

  public void mouseExited(MouseEvent e) {}

  public void mousePressed(MouseEvent e) {}
          
  public void mouseReleased(MouseEvent e)  {}
  
  public void windowActivated(WindowEvent e)  {}
 
  public void windowClosed(WindowEvent e)  {}
  
  /**
  * windowClosing Event occurs when the window is closed by the user or program.
  * 
  * @param      e    the WindowEvent object assosiated with the event.
  **/
  public void windowClosing(WindowEvent e)  {
    // closes the window by disposing of the frame.
    frame.dispose();
    // exits any remaining proccessing and perfoms garbage collection on assosiated memory
    System.exit(0);
  }

  public void windowDeactivated(WindowEvent e)  {}

  public void windowDeiconified(WindowEvent e)  {}

  public void windowIconified(WindowEvent e)  {} 

  public void windowOpened(WindowEvent e)  {}
  
    /**
     * main method, application starts here.
     *
     * @param args execution arguments
     */
    public static void main(String[] args) {
        new LaunchGui();
    }
}
